<?php
	/**
	 * 添加oss图片
	 * Created by:
	 * User: wangs
	 * Date: 2023/11/21
	 */
	declare (strict_types=1);

	namespace app\service;

	use OSS\OssClient;
	use OSS\Core\OssException;

	class InputOss
	{

		protected $url='zzxtwebh5.oss-cn-shanghai.aliyuncs.com';//外网地址
		protected $path='';//文件地址
		protected $file;
		public function setContent($file){
			$this->file=$file;
		}
		public function createObject($file_name,$shop_id){
			$accessKeyId = "LTAIFYJSf9ggWSHH"; ;
			$accessKeySecret = "aKnfmOjffX24UwRey7AesDKfIMpYkR";
			$endpoint = "oss-cn-shanghai.aliyuncs.com";
			$bucket='zzxtwebh5';
			$object ='excel/image/'.$shop_id.'/'.$file_name;
			$content=$this->file;
			try {
				$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
				$ossClient->putObject($bucket, $object, $content);
				$this->path=$object;
			} catch (OssException $e) {
				$this->path='';
				print $e->getMessage();
			}
		}

		public function getUrl(): string
		{
			return $this->url.$this->path;
		}
	}